from rest_framework import serializers
from apps.orders.models import OrderGoods,OrderInfo

class OrderSimpleSerializer(serializers.Serializer):
    order_id = serializers.CharField()
    create_time = serializers.DateTimeField()


class SKuRelatedSerializer(serializers.Serializer):
    #名字
    name = serializers.StringRelatedField()
    default_image = serializers.ImageField()
    #默认地址
class DetailRelatedSerializer(serializers.ModelSerializer):
    #sku 重写 不光要id   这里的sku属于单个的商品不是多个商品
    sku = SKuRelatedSerializer(read_only=True)
    class Meta:
        model = OrderGoods
        fields = ['count','price','sku']
#订单的简单页面只存在 create_id、oreder_id
#订单的详情页 需要很多的数据  故在查询一个时  另外调用一个序列化器
class OrderSerializer(serializers.ModelSerializer):
    #用户
    user = serializers.StringRelatedField(read_only=True)
    #订单商品
    skus = DetailRelatedSerializer(read_only=True,many=True)
    class Meta:
        model = OrderInfo
        fields = "__all__"